The Animation control can play back AVI files so that you can add simple animations to your program. This control supports only AVI files that don't include sound and that aren't in compressed form or that have been compressed using Run-Length Encoding (RLE). Any attempt to play back an AVI file that doesn't follow these rules brings up error message 35752, "Unable to open AVI file."
The Animation control is especially useful for embedding simple animations, such as those that you find in the \Common\Graphics\AVIs subdirectory under the main Microsoft Visual Basic installation directory. For example, you can use this control to display sheets of paper that fly from one folder to another folder while you perform a file copy operation in the background, as shown in Figure 11-1.
Figure 11-1. A demonstration program provided on the companion CD-ROM lets you experiment with the Animation control.
The Animation control exposes three main properties. Two of them, Center and BackStyle, can be set only at design time, and are read-only at run time. If the Center property is True, the AVI file is centered in the Animation control window (instead of being displayed near the upper left corner). The BackStyle property can be 0cc2BackstyleTransparent (the default setting, which displays the background color of the control) or 1-cc2BackstyleOpaque (displays the background of the AVI file). The third property, AutoPlay, can be set at any time. You set it to True to automatically start the playback of any AVI file as soon as it's loaded in the control. (If you make this setting, you must set AutoPlay to False through code to stop playback).
No design-time property determines which AVI file is loaded and displayed at run time. To start an animation through code, you must first open the AVI file, which you do using the Open method:
Animation1.Open "d:\vb6\Graphics\AVIs\filecopy.avi" |
If the AutoPlay property is True, the AVI file starts as soon as it has been loaded in the control. Otherwise, you have to start it through code with the Play method, which has the following syntax:
Play [RepeatCount], [StartFrame], [EndFrame] |
RepeatCount is the number of times the animation must run. (The default is -1, which repeats the animation indefinitely.) StartFrame is the starting frame of the animation (the default is 0, the first frame). EndFrame is the ending frame of the animation (the default is -1, the last frame in the AVI file).
You can choose from two ways to stop an animation, and you must select one or the other according to the method you used to start it. If the animation is in AutoPlay mode, you can stop it only by setting the AutoPlay property to False; if you started the animation with the Play method, you can stop it with the Stop method. If you don't plan to restart the same AVI file immediately, you can release some memory by executing the Close method, as shown in the following code (which assumes that the AutoPlay property is False):
Private Sub cmdStart_Click() Animation1.Open "d:\vb5\graphics\AVIs\filecopy.avi" Animation1.Play End Sub Private Sub cmdStop_Click() Animation1.Stop Animation1.Close End Sub |
The Animation control doesn't expose any custom events. This means, for example, that you can't find out when an animation ends.